home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr50 / mlibv22.zip / DEMO4.BAS < prev    next >
BASIC Source File  |  1993-01-27  |  7KB  |  171 lines

  1. DEFINT A-Z
  2. '******************************** DEMO4.BAS *********************************
  3. '*                                                                          *
  4. '* Demonstrates: SetBoundM                                                  *
  5. '*               InWinM                                                     *
  6. '*               CALLing different pointer shapes.                          *
  7. '*                                                                          *
  8. '* NOTE: In order for this demo to run you must start the QB editor         *
  9. '*     : along with the library MLIBN.QLB  (ie., QB/L MLIBN).               *
  10. '*     :                                                                    *
  11. '*     : IF YOU ARE NOT USING QuickBASIC 4.0- 4.5 SEE PAGE 2 OF THE MANUAL  *
  12. '*     : BEFORE TRYING TO RUN THIS DEMO!                                    *
  13. '*     :                                                                    *
  14. '*                                                                          *
  15. '****************************************************************************
  16. '                                                '
  17. '$INCLUDE: 'mlib.inc'                            '
  18.                                                  '
  19. TYPE WindowType                                  '
  20.       x1 AS INTEGER                              '
  21.       y1 AS INTEGER                              '
  22.       x2 AS INTEGER                              '
  23.       y2 AS INTEGER                              '
  24.       wc AS INTEGER'Win color.                   '
  25. END TYPE                                         '
  26.                                                  '
  27. DECLARE SUB InitWin ()                           '
  28. DECLARE SUB CreateWin ()                         '
  29. DECLARE SUB NumberWin ()                         '
  30. DECLARE FUNCTION ActiveWin ()                    '
  31.                                                  '
  32. DIM SHARED Win(1 TO 8) AS WindowType             '
  33. DIM SHARED WinLB%, WinUB%                        '
  34. WinLB% = LBOUND(Win, 1)                          'Set these vars now, so we
  35. WinUB% = UBOUND(Win, 1)                          'only make one call to get
  36.                                                  'upper/lower bounds.
  37. SCREEN 12: CLS : CALL InitPointer(NumBut%)       '
  38. IF NumBut% = 0 THEN                              '
  39.    SCREEN 0                                      '
  40.    PRINT "No mouse"                              '
  41.    END                                           '
  42. END IF                                           '
  43.                                                  '
  44. CALL SetBoundM(1, 1, 638, 110)                   'Confine pointer to area
  45.                                                  'around windows.
  46.                                                  '
  47. CALL InitWin                                     '
  48. CALL CreateWin                                   '
  49. CALL NumberWin                                   '
  50.                                                  '
  51. LOCATE 10, 1                                     '
  52. PRINT "Clicked in window:"                       '
  53.                                                  '
  54. LOCATE 28, 1                                     '
  55. PRINT "Press a key to end..."                    '
  56. CALL ShowPointer                                 '
  57.                                                  '
  58. DO                                               '
  59.                                                  '
  60.   DO                                             '
  61.                                                  '
  62.      CALL GetButtonM(But%, MX%, MY%)             '
  63.                                                  '
  64.      hWin% = ActiveWin                           'Continuously check which
  65.      SELECT CASE hWin%                           'window pointer is in.
  66.         CASE 1: ARROW0                           'Call a different shape
  67.         CASE 2: HANDV0                           'for each window.
  68.         CASE 3: HOURGLASS0                       'These shapes were created
  69.         CASE 4: PEN0                             'by: ME.EXE(mouse editor)
  70.         CASE 5: MAGNIFYGLASS0                    'CVTASM.EXE(convert-assembly)
  71.         CASE 6: PAINTCUP0                        'assembled(MASM compatible)
  72.         CASE 7: MOUSE0                           'linked to MLIB. ME/CVTASM
  73.         CASE 8: WATCH0                           'included in registered ver.
  74.      CASE ELSE: ARROW1                           'Not in a window, call
  75.                 hWin% = 0                        'default shape.
  76.      END SELECT                                  '
  77.                                                  '
  78.      IF LEN(INKEY$) THEN SCREEN 0: END           '
  79.                                                  '
  80.   LOOP UNTIL But%                                '
  81.                                                  '
  82.   IF hWin% THEN                                  'Pointer is in a window.
  83.                                                  'do some things and stuff.
  84.      x1 = Win(hWin%).x1                          '
  85.      y1 = Win(hWin%).y1                          '
  86.      x2 = Win(hWin%).x2                          '
  87.      y2 = Win(hWin%).y2                          '
  88.      DIM Box(1 TO 1822)                          '
  89.      HidePointer                                 '
  90.      GET (x1, y1)-(x2, y2), Box                  '
  91.      PUT (162, 135), Box, PSET                   '
  92.      ShowPointer                                 '
  93.   END IF                                         '
  94.                                                  '
  95.   WHILE But%                                     'Loop while button is down.
  96.      CALL GetButtonM(But%, MX%, MY%)             '
  97.   WEND                                           '
  98.                                                  '
  99. LOOP                                             '
  100.  
  101. FUNCTION ActiveWin
  102.  
  103. ActiveWin = 0 'Prove otherwise.
  104.  
  105. FOR El = WinLB% TO WinUB%                        'Check first through last
  106.                                                  'Win(?) element, or until
  107.                                                  'a match is made.
  108.    x1 = Win(El).x1 'Easier to read.
  109.    y1 = Win(El).y1
  110.    x2 = Win(El).x2
  111.    y2 = Win(El).y2
  112.  
  113.                                                  'NOTE! InWinM always checks
  114.                                                  'current pointer position.
  115.                                                  'InWinM returns -1, if true.
  116.  
  117.    IF InWinM(x1, y1, x2, y2) THEN                'Pointer is inside Win(?),
  118.                                                  'return element number.
  119.       ActiveWin = El
  120.       EXIT FOR
  121.      
  122.    END IF
  123.  
  124. NEXT El
  125.  
  126. END FUNCTION
  127.  
  128. SUB CreateWin
  129. 'Draw 8 windows.
  130.  
  131. FOR Num% = LBOUND(Win, 1) TO UBOUND(Win, 1)
  132.  
  133. LINE (Win(Num%).x1, Win(Num%).y1)-(Win(Num%).x2, Win(Num%).y2), Win(Num%).wc, B
  134. LINE (Win(Num%).x1 + 2, Win(Num%).y1 + 2)-(Win(Num%).x2 - 2, Win(Num%).y2 - 2), Win(Num%).wc, BF
  135.  
  136. NEXT Num%
  137.  
  138. END SUB
  139.  
  140. SUB InitWin
  141. 'Initialize Win() array.
  142.  
  143. Y = 0
  144.  
  145. FOR X = 1 TO 640 STEP 80
  146.   
  147.    Y = Y + 1
  148.   
  149.    Win(Y).x1 = X
  150.    Win(Y).y1 = 10
  151.    Win(Y).x2 = X + 72
  152.    Win(Y).y2 = 100
  153.    Win(Y).wc = Y   'win color.
  154.  
  155. NEXT
  156.  
  157. END SUB
  158.  
  159. SUB NumberWin
  160. 'Number each window.
  161.  
  162. FOR X = 1 TO 80 STEP 10
  163.  
  164.    LOCATE 2, X + 3
  165.    PRINT X \ 10 + 1
  166.  
  167. NEXT
  168.  
  169. END SUB
  170.  
  171.